<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<? session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>BINDER - HOME</title>
		<link rel="stylesheet" type="text/css" href="style2.css" title="style2" />
		<script type="text/javascript" src="script.js"></script>
		<script type="text/javascript" src="like.js"></script>
	</head>
	<body>
		<div id="wrapper">
			<div id="header"><? include('header.php'); ?></div>
			<div id="main">
				<div id="home-most-liked">
					<div class="home-atas-like">
					</div>
					<div class="home-tengah">
						<div id="most-liked-judul">
							MOST LIKED
						</div>
						<?php
							require("dbfunc.php");
							require("datefunc.php");
							$qres = mysql_query("SELECT * FROM konten ORDER BY jmlLike DESC LIMIT 0,3");
							if($qres){
								while($row = mysql_fetch_array($qres))
								{
									echo "<div class='line'></div>";
									echo "<div class='home-judul'>";
										echo "<a href='konten.php?jd=".$row['judul']."'>".$row['judul']."</a>";
									echo "</div>";
									echo "<div class='isi'>";
										//isi if 1 then link, 2 then gambar, 3 then video
										$tipe=$row['tipe'];
										switch ($tipe){
											case 1:	//link
												echo "<div class='isi-link'><a href='".$row['url']."'>Lihat link terkait</a></div>";
												echo "<br />Penjelasan :";
												echo "<div class='isi-about'>".$row['about']."</div>";
												break;
											case 2:	//gambar
												echo "<div class='isi-gambar'><a href='konten.php?jd=".$row['judul']."'><img class='dynamic-img' src='konten/".$row['judul'].".jpg' alt='".$row['judul']."' /></a></div>";
												break;
											case 3:	//video
												echo "<iframe allowfullscreen='' width='310' height='225' frameborder='0' src='".$row['url']."'></iframe>";
												break;
											default:
												break;
										}
									echo "</div>";
									echo "<div class='home-detail'>";
										echo "<div class='byon'>";
											echo "Dipost oleh <strong><span class='by'><a href='profile.php?uid=".$row['userpost']."'>".$row['userpost']."</a></span></strong> pada <strong>".diffDate($row['tgl'],date('d-m-Y H:i:s'))."</strong>";
										echo "</div>";
										echo "<div class='commenter'>";
											echo "<strong><span>".$row['jmlKom']."</span></strong> komentar";
										echo "</div>";
										echo "<div class='likedislike'>";
											echo "<ul class='ldbuttons'>";
												if (isset($_SESSION['username'])){
												if(strcmp($_SESSION['username'],$row['userpost'])!=0){
										$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$_SESSION['username']."'");
								if (mysql_num_rows($result)>0){
									//sudah like/dislike
									$baris = mysql_fetch_array($result);
									if ($baris['jenis']==1){	//like
										echo "<li class='islike' id='mlblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
										echo "<li class='notdislike' id='mlbdislike".$row['id']."'></li>";
									}else{
										//dislike
										echo "<li class='notlike' id='mlblike".$row['id']."'></li>";
										echo "<li class='isdislike' id='mlbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									}
								}else{
									//bisa like/dislike
									echo "<li class='like' id='mlblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									echo "<li class='dislike' id='mlbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
								}
										}else{
													$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$row['userpost']."'");
													if (mysql_num_rows($result)>0){
														//sudah like/dislike
														$baris = mysql_fetch_array($result);
														if ($baris['jenis']==1){	//like
															echo "<li class='islike' id='mlblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
															echo "<li class='notdislike' id='mlbdislike".$row['id']."'></li>";
														}else{
															//dislike
															echo "<li class='notlike' id='mlblike".$row['id']."'></li>";
															echo "<li class='isdislike' id='mlbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
														}
													}else{
														//bisa like/dislike
														echo "<li class='like' id='mlblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
														echo "<li class='dislike' id='mlbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
													}
												}
												}else{
													//tidak bisa apa-apa
													echo "<li class='like' id='mlblike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
													echo "<li class='dislike' id='mlbdislike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
												}
											echo "</ul>";
										echo "</div>";
										echo "<div class='count'>";
											echo "<strong><span id='jmllikea".$row['id']."'>".$row['jmlLike']."</span></strong> user menyukai";
										echo "</div>";
										echo "<div class='clear'>";
										echo "</div>";
									echo "</div>";
								}
							}
						?>
					</div>
					<div class="home-bawah-like">
					</div>
				</div>
				<div id="home-most-commented">
					<div class="home-atas-komen">
					</div>
					<div class="home-tengah">
						<div id="most-commented-judul">
							MOST COMMENTED
						</div>
						<?php
							$qres = mysql_query("SELECT * FROM konten ORDER BY jmlKom DESC LIMIT 0,3");
							if ($qres){
								while($row = mysql_fetch_array($qres))
								{
									echo "<div class='line'></div>";
									echo "<div class='home-judul'>";
										echo "<a href='konten.php?jd=".$row['judul']."'>".$row['judul']."</a>";
									echo "</div>";
									echo "<div class='isi'>";
										//isi if 1 then link, 2 then gambar, 3 then video
										$tipe=$row['tipe'];
										switch ($tipe){
											case 1:	//link
												echo "<div class='isi-link'><a href='".$row['url']."'>Lihat link terkait</a></div>";
												echo "<br />Penjelasan :";
												echo "<div class='isi-about'>".$row['about']."</div>";
												break;
											case 2:	//gambar
												echo "<div class='isi-gambar'><a href='konten.php?jd=".$row['judul']."'><img class='dynamic-img' src='konten/".$row['judul'].".jpg' alt='".$row['judul']."' /></a></div>";
												break;
											case 3:	//video
												echo "<iframe allowfullscreen='' width='310' height='225' frameborder='0' src='".$row['url']."'></iframe>";
												break;
											default:
												break;
										}
									echo "</div>";
									echo "<div class='home-detail'>";
										echo "<div class='byon'>";
											echo "Dipost oleh <strong><span class='by'><a href='profile.php?uid=".$row['userpost']."'>".$row['userpost']."</a></span></strong> pada <strong>".diffDate($row['tgl'],date('d-m-Y H:i:s'))."</strong>";
										echo "</div>";
										echo "<div class='commenter'>";
											echo "<strong><span>".$row['jmlKom']."</span></strong> komentar";
										echo "</div>";
										echo "<div class='likedislike'>";
											echo "<ul class='ldbuttons'>";
												if (isset($_SESSION['username'])){
												if(strcmp($_SESSION['username'],$row['userpost'])!=0){
										$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$_SESSION['username']."'");
								if (mysql_num_rows($result)>0){
									//sudah like/dislike
									$baris = mysql_fetch_array($result);
									if ($baris['jenis']==1){	//like
										echo "<li class='islike' id='mcblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
										echo "<li class='notdislike' id='mcbdislike".$row['id']."'></li>";
									}else{
										//dislike
										echo "<li class='notlike' id='mcblike".$row['id']."'></li>";
										echo "<li class='isdislike' id='mcbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									}
								}else{
									//bisa like/dislike
									echo "<li class='like' id='mcblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
									echo "<li class='dislike' id='mcbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
								}
										}else{
													$result=mysql_query("SELECT * FROM menyukai WHERE idKonten = '".$row['id']."' AND user = '".$row['userpost']."'");
													if (mysql_num_rows($result)>0){
														//sudah like/dislike
														$baris = mysql_fetch_array($result);
														if ($baris['jenis']==1){	//like
															echo "<li class='islike' id='mcblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
															echo "<li class='notdislike' id='mcbdislike".$row['id']."'></li>";
														}else{
															//dislike
															echo "<li class='notlike' id='mcblike".$row['id']."'></li>";
															echo "<li class='isdislike' id='mcbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
														}
													}else{
														//bisa like/dislike
														echo "<li class='like' id='mcblike".$row['id']."'><a href=\"javascript:mlike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
														echo "<li class='dislike' id='mcbdislike".$row['id']."'><a href=\"javascript:mdislike(".$row['id'].",'".$_SESSION['username']."')\"></a></li>";
													}
												}
												}else{
													//tidak bisa apa-apa
													echo "<li class='like' id='mcblike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
													echo "<li class='dislike' id='mcbdislike".$row['id']."'><a href=\"javascript:alert('Login dahulu untuk melakukan ini ^^v')\"></a></li>";
												}
											echo "</ul>";
										echo "</div>";
										echo "<div class='count'>";
											echo "<strong><span id='jmllikeb".$row['id']."'>".$row['jmlLike']."</span></strong> user menyukai";
										echo "</div>";
										echo "<div class='clear'>";
										echo "</div>";
									echo "</div>";
								}
							}
						?>
					</div>	
					<div class="home-bawah-komen">
					</div>
				</div>
				<div id="sidebar"><? include('sidebar.php'); ?></div>
			</div>
			<div id="footer"><? include('footer.php'); ?></div>
		</div>
		<script type="text/javascript" src="home.js"></script>
	</body>
</html>